<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Teacher/index')}">请假列表</a></li>
        <if condition="$is_teacher eq 1">
        <li><a href="{:url('Teacher/add', ['is_teacher'=>$is_teacher])}">添加</a></li>
        </if>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('Teacher/index')}">
        <if condition="$is_teacher eq 1">
            <label class="form-group col-lg-4 col-md-6">
            请假日期:
            <input type="text" class="form-control" name="start"
                   value="{$param.start|default=''}"
                   autocomplete="off"> -
            <input type="text" class="form-control" name="end"
                   value="{$param.end|default=''}"
                   autocomplete="off">
            </label>
        <else/>
            <label class="form-group col-lg-4 col-md-6">
                授课老师:
                <input type="text" class="form-control" name="teacher_name"
                       value="{$param.teacher_name|default=''}" placeholder="按老师姓名搜索">
            </label>
        </if>

        <label class="form-group col-lg-4 col-md-6">
             <input type="submit" class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('Teacher/index')}">清空</a>
        </label>
    </form>

    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('Teacher/delete')}" data-subcheck="true" data-msg="您确定删除吗？">批量删除
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th>编号</th>
                <th>老师</th>
                <!--<th>校区</th>-->
                <th>班级</th>
                <th>请假原因</th>
                <th>请假课时</th>
                <th>代课老师</th>
                <th>操作</th>
            </tr>
            </thead>
            <notempty name="leaves">
                <foreach name="leaves" item="vo">
                    <tr>
                        <td>
                            <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                                   value="{$vo.id}" title="ID:{$vo.id}">
                        </td>
                        <td>{$vo.id}</td>
                        <td>{$vo.teacher_name}</td>
                        <!--<td>{$vo.campus_name}</td>-->
                        <td>{$vo.class_name}</td>
                        <td>{$vo.reason}</td>
                        <td>{:date('Y-m-d',$vo.leave_date)} {$vo.leave_start_time}~{$vo.leave_end_time}</td>
                        <td>{$vo.supply_name}</td>
                        <td>
                            <if condition="$is_teacher eq 1">
                                <a href="{:url('Teacher/edit',array('id'=>$vo['id'],'is_teacher'=>$is_teacher))}">{:lang('EDIT')}</a>
                            <else/>
                                <a href="javascript:;" data-title="{$vo.id}" id="handle_teacher">添加代课老师</a> |
                                <a href="{:url('Teacher/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                            </if>
                        </td>
                    </tr>
                </foreach>
            </notempty>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>

<div id="add_teacher" style="display: none;">
    <form action="" class="row well" style="margin:0;">
        <input type="hidden" name="leave_id" id="leave_id" value="0">

        <label for="supply_teacher" class="form-group col-xs-3">代课老师:</label>
        <select class="form-control" name="supply_teacher" id="supply_teacher" style="width:179px;">
            <notempty name="teachers">
                <volist name="teachers" id="vo">
                    <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                        <option value="{$vo.id}" selected>{$vo.user_name}</option>
                    <else/>
                        <option value="{$vo.id}">{$vo.user_name}</option>
                    </if>
                </volist>
            </notempty>
        </select>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    $('input[name="start"]').datepicker();
    $('input[name="end"]').datepicker();

    $(document).on('click','#handle_teacher',function () {
        var leave_id = $(this).data('title');
        $('#leave_id').val(leave_id);

        layer.open({
            type: 1,
            btn: ['提交'],
            title: '添加代课老师',
            content: $('#add_teacher'),
            yes: function (index, layero) {
                loading = layer.load(0, { shade: false });
                add_supply_teacher();
            }
        });
    });

    //添加代课老师
    function add_supply_teacher() {
        var leaveId = $('#leave_id').val();
        var teacher_id = $('#supply_teacher').val();
        if(leaveId == 0 || teacher_id == 0){
            return false;
        }

        $.ajax({
            url:"{:url('Teacher/addTeacher')}",
            type:'post',
            dataType:'json',
            data:{"leave_id":leaveId,"supply_teacher":teacher_id},
            success:function(jsonData){
                layer.msg(jsonData.Message, { icon: jsonData.Status, time: 1500 }, function () {
                    layer.closeAll();
                    window.location.reload();
                });
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
            }
        });

    }
</script>
</body>